package net.inxweb.bluemeerkat.web.rest.service.glossary.type;

import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryInstance;
import net.inxweb.bluemeerkat.domain.model.glossary.GlossaryType;
import net.inxweb.bluemeerkat.domain.repository.GlossaryInstanceRepository;
import net.inxweb.bluemeerkat.domain.repository.GlossaryTypeRepository;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Path("glossary")
@Transactional
public class GlossaryTypeService { 
	@Resource(name="glossaryTypeRepositoryHibernate")
	private GlossaryTypeRepository glossaryTypeRepository;
	
	@Resource(name="glossaryInstanceRepositoryHibernate")
	private GlossaryInstanceRepository glossaryInstanceRepository;
	

	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public Long createGlossaryInstance(GlossaryInstance glossaryInstance) { 
		return glossaryInstanceRepository.add(glossaryInstance);
	}
	
	@POST
	@Path("/type/all")
    @Produces(MediaType.APPLICATION_JSON)	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public Long createGlossaryType(GlossaryType glossaryType) {
		return glossaryTypeRepository.add(glossaryType);
	}
	
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public void modifyGlossaryInstance(GlossaryInstance glossaryInstance) {
		glossaryInstanceRepository.modify(glossaryInstance);
	}
	
	@PUT
	@Path("/type/all")
    @Produces(MediaType.APPLICATION_JSON)		
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED) 
	public void modifyGlossaryType(GlossaryType glossaryType) {
		glossaryTypeRepository.modify(glossaryType); 
	} 

	public List<GlossaryInstance> findAllGlossaryInstance() {
		return glossaryInstanceRepository.findAll();
	}
	
	@GET
	@Path("/type/all")
    @Produces(MediaType.APPLICATION_JSON)
	public List<GlossaryType> findAllGlossaryType() { 
		return glossaryTypeRepository.findAll();
	}
	

	public GlossaryInstance findGlossaryInstance(Long id) {
		return glossaryInstanceRepository.find(id);
	}
	
	@GET
	@Path("/type/{id}")
    @Produces(MediaType.APPLICATION_JSON)
	public GlossaryType findGlossaryType(Long id) { 
		return glossaryTypeRepository.find(id);
	}
}
